package edu.bupt.e1btree;

public class T41MinimumDepth {

    private int min = Integer.MAX_VALUE;

    public int minDepth(TreeNode root) {
        if (null == root) return 0;
        dep(root,0);
        return min;
    }

    private void dep(TreeNode root,int cur){
        if (null == root.left && null == root.right){
            min = Math.min(min,cur+1);
        }
        if (null != root.right) dep(root.right,cur + 1);
        if (null != root.left) dep(root.left,cur + 1);
    }
}
